package com.agy.filemanager.service.impl;

import com.agy.filemanager.entity.FileInfo;
import com.agy.filemanager.mapper.FullSearchMapper;
import com.agy.filemanager.service.FullSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 全文检索
 */
@Service
public class FullSearchServiceImpl implements FullSearchService{

    @Autowired
    private FullSearchMapper fullSearchMapper;

    /**
     * 全文检索（模糊查询）
     * @return
     */
    @Override
    public List<FileInfo> selectByFullSearch(String keywords) {
        Example example = new Example(FileInfo.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andLike("filename","%"+keywords+"%");//文件名模糊查询
        example.setOrderByClause("uploadtime desc");     //上传时间倒序
        criteria.andEqualTo("isyes","1");//是否有效
        List<FileInfo> list = this.fullSearchMapper.selectByExample(example);
        return list;
    }
}
